home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d13 / pj9_3.arc / COMMAND.ASM < prev    next >
Assembly Source File  |  1991-10-07  |  4KB  |  77 lines

  1.         PAGE    ,105
  2.         TITLE   Command Line
  3.         .MODEL  MEDIUM
  4. ;***********************************************************************
  5. ;                           COMMAND.ASM                                *
  6. ;   COMMAND(<string>) [DECLARE SUB COMMAND (A$)] is an assembled       *
  7. ; subroutine to be linked to programs compiled with Microsoft BC v.    *
  8. ; 7.0 (or later) to insert "the rest of the command line" in the       *
  9. ; Program Segment Prefix before starting another program with the "RUN * 
  10. ; <filename>" command.  This version will operate correctly for        *
  11. ; programs compiled in either the "near string" or "far string" mode.  *
  12. ;   Call with:  CALL COMMAND(<string>)                                 *
  13. ;       where <string> is the argument string to be returned by the    *
  14. ;       new program.  (If the new program was compiled from BASIC, the *
  15. ;       text string will be returned by COMMAND$ with all lower-case   *
  16. ;       letters converted to upper case.)                              *
  17. ;   If LEN(<string>) > 125, a null argument string will be inserted    *
  18. ; instead.                                                             *
  19. ;----------------------------------------------------------------------*
  20. ;               Written by M. L. Lesser, March 30, 1990                *
  21. ;    Based on the BC version 4.0 module of the same name, written for  *
  22. ; the book "Advanced QuickBASIC 4.0," published by Bantam Books, 1988. *
  23. ;                 Assembled with Microsoft MASM v. 5.1                 *
  24. ;***********************************************************************
  25.  
  26. EXTRN StringAddress:FAR                 ;"Mixed language" functions
  27. EXTRN StringLength:FAR                  ; added to BC 7.0 libraries
  28.  
  29. .CODE
  30.         PUBLIC COMMAND
  31. COMMAND PROC
  32. ; Save critical registers used:
  33.         PUSH    BP
  34.         MOV     BP,SP
  35.         PUSH    DS
  36.         PUSH    SI
  37.         PUSH    DI
  38. ; Get string-argument length first:
  39.         PUSH    6[BP]                   ;Argument for StringLength
  40.         CALL    StringLength            ; (offset of string descriptor)
  41.         PUSH    AX                      ;Function return in AX
  42. ; Get address of string:
  43.         PUSH    6[BP]
  44.         CALL    StringAddress           ;Function returns far address
  45.         MOV     DS,DX                   ; pointer in DX:AX
  46.         MOV     SI,AX
  47. ; Get PSP segment address:
  48.         MOV     AH,51H                  ;Undocumented DOS call
  49.         INT     21H                     ;  returns PSP segment address
  50.         MOV     ES,BX                   ;  in BX
  51.         MOV     DI,80H                  ;Start of argument pointer
  52. ; Insert string in command line in proper form:
  53.         POP     CX                      ;String length
  54.         OR      CX,CX                   ;Is it null string?
  55.         JZ      NULL
  56.         CMP     CX,7DH                  ;Is it within length limit?
  57.         JA      NULL                    ;If not, replace with null
  58.         MOV     AL,CL                   ;Number of bytes in string
  59.         INC     AL                      ;Add one for leading <SP>
  60.         STOSB                           ;Store command-line byte count
  61.         MOV     AL,' '                  ;Insert leading <SP>
  62.         STOSB
  63.         REP     MOVSB                   ;Move text of <string>
  64. DONE:   MOV     AL,0DH                  ;Add trailing <CR>
  65.         STOSB
  66.         POP     DI
  67.         POP     SI
  68.         POP     DS
  69.         POP     BP
  70.         RET     2
  71. NULL:   XOR     AL,AL                   ;Forces null command line
  72.         STOSB
  73.         JMP     DONE
  74. COMMAND ENDP
  75.  
  76.         END
  77.